1C - Ancient Berland Circus - CodeForces Solution


geometry math *2100

Please click on ads to support us..

Python Code:

from math import *
p =[list(map(float,input().split())) for i in range(3)]  
a,b,c=[hypot(x1-x2,y1-y2) for (x1,y1),(x2,y2) in [(p[0],p[1]),(p[0],p[2]),(p[1],p[2])]]
A,B,C=[acos((y*y+z*z-x*x)/2/z/y) for x,y,z in [(a,b,c),(b,c,a),(c,a,b)]]
R=a/2/sin(A)     
def g(x,y):return x if y<1e-3 else g(y,fmod(x,y))
u=2*g(A,g(B,C))
print(round(R * R * pi / u * sin(u),7))

C++ Code:

#include<cstdio>
#include<cmath>
#include<cstdlib>
#define PI 3.141592654

double point[3][2],ql[3],cosa[3],qsina[3],qr,s;
unsigned i,a[3],res,g,b[3]={0},c[3],d,mind;

int main()
{
  for(i=0;i<3;i++)
  	scanf("%lf%lf",&point[i][0],&point[i][1]);
  for(i=0;i<3;i++)
  	ql[i]=(point[i][0]-point[(i+1)%3][0])*(point[i][0]-point[(i+1)%3][0])+(point[i][1]-point[(i+1)%3][1])*(point[i][1]-point[(i+1)%3][1]);
  for(i=0;i<3;i++)
  {
    cosa[i]=(ql[(i+2)%3]+ql[(i+1)%3]-ql[i])/(2*sqrt(ql[(i+1)%3])*sqrt(ql[(i+2)%3]));
  	qsina[i]=1-cosa[i]*cosa[i];
	a[i]=acos(cosa[i])*1e5;
  }
  qr=(ql[0]/qsina[0]+ql[1]/qsina[1]+ql[2]/qsina[2])/12;
  b[0]=b[1]=b[2]=1;
  mind=~0;
  do
  {
  	c[0]=a[0]/b[0];
  	c[1]=a[1]/b[1];
  	c[2]=a[2]/b[2];	
  	d=abs(c[0]-c[1])+abs(c[1]-c[2])+abs(c[2]-c[0]);
  	if(mind>d)
  	{
  	  mind=d;
  	  res=b[0]+b[1]+b[2];
	}
	
	i=0;
	if(a[0]/b[0]<a[1]/b[1])
  	  i=1;
  	if(a[i]/b[i]<a[2]/b[2])
  	  i=2;
  	++b[i];
  }while(b[0]+b[1]+b[2]<=100);
  s=qr*sin(2*PI/res)*res/2;
  printf("%.8lf\n",s);
  return 0;
}

 		    	   	 	 	  		   		    		


Comments

Submit
0 Comments
More Questions

911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments
1428B - Belted Rooms
519B - A and B and Compilation Errors
1152B - Neko Performs Cat Furrier Transform
1411A - In-game Chat
119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String